package com.pm.main.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

/**
 * @author admin
 * @date 2020/11/2
 **/
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("分页-参数")
public class PageReq {
    @Setter
    @ApiModelProperty("页")
    private int page;
    @Getter
    @Setter
    @ApiModelProperty("每页数量")
    private int size;

    public static final PageReq DEFAULT_PAGE = new PageReq(1, 10);

    public int getPage() {
        return Math.max(page - 1, 0);
    }

    public <T> List<T> subList(List<T> list) {
        final int offset =  getPage()  * size;
        return list.subList(offset, Math.min(offset + size, list.size()));
    }
}
